package com.xiaoniu.lib_keleim.pojo.dos;


import com.xiaoniu.lib_keleim.MessageType;
import com.xiaoniu.lib_keleim.pojo.vos.BaseMessage;
import com.xiaoniu.lib_keleim.utils.GsonUtil;

import io.realm.RealmObject;
import io.realm.annotations.Ignore;
import io.realm.annotations.PrimaryKey;


public class MessageEntity extends RealmObject {
    @PrimaryKey
    public long messageId;
    //目标
    public long targetId;
    //发送人用户ID
    public long userId;
    //会话类型 聊天室:0 私聊 :1
    public byte conversationType;
    //消息类型
    public byte msgType;
    //1 发送中 2 失败 3 取消 4 成功
    public byte sentStatus;
    //1 未读 2 已读
    public byte receivedStatus;
    //消息发生时间
    public long timestamp;
    //消息内容
    public String content;
    //0 server 1 android 2 ios 3 web 4 pc
    public byte platformIdentity = 1;
    //额外的信息
    public String ext;
    @Ignore
    public UserEntity sendUser;

    public BaseMessage toMessageChatVO(){
        BaseMessage messageEntity = new BaseMessage();
        messageEntity.messageId = messageId;
        messageEntity.targetId = targetId;
        messageEntity.userId = userId;
        messageEntity.conversationType = conversationType;
        messageEntity.msgType = msgType;
        messageEntity.timestamp = timestamp;
        messageEntity.content = content;
        messageEntity.platformIdentity = platformIdentity;
        messageEntity.sendUser = sendUser;

        return messageEntity;
    }

    public void setExt(Object ext) {
        if (ext!=null && !(ext instanceof String)) {
            this.ext = GsonUtil.toJson(ext);
        }
    }


}
